﻿/* 
	PureMVC CSharp / WPF / EmployeeAdmin Demo - Login
	By Andy Adamczak <andy.adamczak@puremvc.org>
	Copyright(c) 2009 Andy Adamczak, Some rights reserved.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace GEF2.Model.Storage
{
	public class Entity
	{
        public int mX;
        public int mY;
        public int mWidth;
        public int mHeight;
        private int mLineWidth;
        private System.Drawing.Rectangle mBoundingBox;

		public Entity()
		{
            mLineWidth = 1;
            mX = 100;
            mY = 100;
            mWidth = 100;
            mHeight = 100;
            updateBoundingBox();
		}

		public Entity(string uname)
		{
			if (uname != null) m_Name = uname;
            mLineWidth = 1;
            mX = 100;
            mY = 100;
            mWidth = 100;
            mHeight = 100;
            updateBoundingBox();
		}

        public Entity(string uname, int x, int y)
        {
            if (uname != null) m_Name = uname;
            mLineWidth = 1;
            mX = x;
            mY = y;
            mWidth = 100;
            mHeight = 100;
            updateBoundingBox();
        }

		public string Name
		{
            get { return m_Name; }
		}
        private string m_Name = "";

		public bool IsValid
		{
            get { return !string.IsNullOrEmpty(Name); }
		}

        public void draw(System.Drawing.Graphics canvas)
        {
            using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, mLineWidth))
            {
                canvas.DrawRectangle(pen, new System.Drawing.Rectangle(mX, mY, mWidth, mHeight));
            }
        }

        private void updateBoundingBox()
        {
            mBoundingBox = new System.Drawing.Rectangle(mX - mLineWidth / 2, mY - mLineWidth / 2, mWidth + mLineWidth, mHeight + mLineWidth);
        }

        public System.Drawing.Rectangle boundingBox()
        {
            return mBoundingBox;
        }

        //public System.Drawing.Rectangle BoundingBox()
        //{
        //    return new System.Drawing.Rectangle(mX - mLineWidth / 2, mY - mLineWidth / 2, mWidth + mLineWidth, mHeight + mLineWidth); 
        //}

        public bool containsRect(System.Drawing.Rectangle rect)
        {
            return mBoundingBox.IntersectsWith(rect);
        }

        public bool containsPoint(System.Drawing.Point point)
        {
            return mBoundingBox.Contains(point);
        }

        public void select(System.Drawing.Graphics canvas, bool selected)
        {
            
            mLineWidth = selected ? 10 : 1;
            updateBoundingBox();
            draw(canvas);
        }


	}
}
